package tp2lab;
import java.util.*;

public final class Deck {
	private List<Card> lista;
	Deck(){
	    Card [] talia;
	    talia = new Card[52];
	    String [] kolory = { "pik", "kier", "karo", "trefl"};
        // tworzenie talii - tablicy objektow klasy Card
        for(int i = 0; i < 4; ++i){
            String kolor = kolory[i];
            for(int j = 0; j < 13; ++j){
                String figura = "";
                if(j < 9)
                    figura = Integer.toString(j + 2);
                else{
                    if(j == 9)
                        figura = "J";
                    else if(j == 10)
                        figura = "Q";
                    else if(j == 11)
                        figura = "K";
                    else if(j == 12)
                        figura = "A";
                }
                talia[i * 13 + j] = new Card(figura, kolor, j + 2);
            }
        }
	    
	    Random rand = new Random();
	       for(int i = 0; i < 777; ++i){
	            int j, k;
	            do{
	                j = rand.nextInt(52);
	                k = rand.nextInt(52);
	            }while(j == k);
	            Card tmp = talia[j];
	            talia[j] = talia[k];
	            talia[k] = tmp;
	        }
	    
		lista = new ArrayList<Card>();

		    add(talia);
	}
	
	private void add(Card [] talia){
		for(int i = 0; i < 52; ++i){
			lista.add(talia[i]);
		}
	}
	
	private void delete(Card karta){
		lista.remove(karta);
	}

	
	public Card drawCard(){
		Card tmp = lista.get(0);
		delete(tmp);
		return tmp;
	}
}